angular.module('sale.controllers', ['sale.services'])

.controller('SaleCtrl', function($scope,SalesService) {

	// 获取今日销售数据
	SalesService.analytic($scope,{},function(data){
		$scope.saleAnalytics=data;
	});

	$scope.initChart=function(type){
		if(!$scope['labels'+type]){
			SalesService.setChartData($scope,{},type,function(labels,data){
				//对应图表的相应属性
				$scope['labels'+type] = labels;
				$scope['data'+type] = data;
        // console.log($scope['data'+type]);
			});
		}
	};
	$scope.$on('$ionicView.enter', function(e) {
		$scope.initChart('brand');
	});
})

//品牌销售统计列表
.controller('BrandSaleCtrl', function($scope, SalesService) {
	SalesService.list($scope,{},'brand',function(data){
		$scope.brandList = data;
	});
})

//单个品牌销售详情
.controller('BrandSaleDetailCtrl', function($scope, $stateParams,SalesService) {
	$scope.brandName = $stateParams.brandName;
	SalesService.brandSaleDetail($scope,{},$scope.brandName,function(list){
		$scope.brandDetail = list;
	});
})

//机型销售统计列表
.controller('TypeSaleCtrl', function($scope, SalesService) {
	SalesService.list($scope,{},'model',function(list){
		$scope.typeList = list;
	});
})

//门店业绩统计列表
.controller('StoreSaleCtrl', function($scope,SalesService) {
	SalesService.list($scope,{},'store',function(list){
		$scope.storeList = list;
	});
	$scope.onClick = function (points, evt) {
	  console.log(points, evt);
	};
	$scope.onHover = function (points) {
	  if (points.length > 0) {
	    console.log('Point', points[0].value);
	  } else {
      console.log('No point');
	  }
	};
})

//销售员业绩统计列表
.controller('SellerSaleCtrl', function($scope, SalesService) {
	SalesService.list($scope,{},'seller',function(list){
		$scope.sellerList = list;
	});
});
